1
00:00:00,390 --> 00:00:01,859
The next step is to add a setter.

2
00:00:03,890 --> 00:00:07,400
Every field needs a center, the parts field, it's private, yet it doesn't have one.

3
00:00:07,820 --> 00:00:10,280
This means we have no way of updating it from outside.

4
00:00:13,670 --> 00:00:16,400
So in this lesson, we're going to add a setter for the parts field.

5
00:00:18,450 --> 00:00:23,700
We need to add a setter, because right now we have no way of updating the parts array, so inside the

6
00:00:23,700 --> 00:00:27,540
car class at the very bottom, make sure the center is public.

7
00:00:33,000 --> 00:00:37,980
Is lower camel case, it's going to start with the word set and end with the field name, it's going

8
00:00:37,980 --> 00:00:40,440
to accept a parameter string parts.

9
00:00:44,400 --> 00:00:51,240
And using a raised copy of set the parts field of the current object equal to a copy of the parameter.

10
00:00:59,090 --> 00:01:01,550
And we're going to copy the full length of its elements.

11
00:01:06,250 --> 00:01:11,980
All right, now, back in May, instead of spare keys, let's say the second Nissan comes with a spare

12
00:01:11,980 --> 00:01:15,880
filter, but instead of creating another variable, I'm going to call this setar.

13
00:01:22,980 --> 00:01:25,710
And I'm going to directly pass in a new string array.

14
00:01:27,540 --> 00:01:28,530
With two elements.

15
00:01:29,860 --> 00:01:31,120
Tires and filter.

16
00:01:37,510 --> 00:01:42,340
By the way, this is the syntax we use to directly pass in an array without having to store it in a

17
00:01:42,340 --> 00:01:42,790
variable.

18
00:01:44,540 --> 00:01:50,120
It's also the same syntax that you would use to directly return an array once again without having to

19
00:01:50,120 --> 00:01:51,650
store it in a variable first.

20
00:01:53,220 --> 00:01:57,570
I showed you the syntax during the tic tac toe challenge, and it was also in your cheat sheet of module

21
00:01:57,570 --> 00:02:02,040
one, but in case you missed it, I also included the syntax in the current cheat sheet.

22
00:02:04,640 --> 00:02:06,080
Anyways, we can run the code.

23
00:02:15,010 --> 00:02:18,370
And perfect, our getters and setters are working as they should.

24
00:02:21,190 --> 00:02:27,460
The object calls the center passing in an array, Gever runs set parts, which receives the array as

25
00:02:27,460 --> 00:02:28,090
a parameter.

26
00:02:32,180 --> 00:02:35,960
The center sets the parts field equal to a copy of the parts parameter.

27
00:02:36,920 --> 00:02:39,680
And because this works, we're done updating the big three.

28
00:02:41,400 --> 00:02:47,280
Every field is protected by the private keyword, and the getters protect each field as well by returning

29
00:02:47,280 --> 00:02:52,670
a copy of it, and the setters allow us to update each field without having direct access to it.

30
00:02:55,710 --> 00:02:59,490
In this lesson, you added a setter and finally we're done fixing stuff.

31
00:03:00,620 --> 00:03:06,500
Every time you add a new field, you need to update the big three, namely the constructors getters

32
00:03:06,500 --> 00:03:07,340
and setters.

33
00:03:09,580 --> 00:03:13,930
You started by fixing your constructor and now it updates every field when it runs.

34
00:03:28,430 --> 00:03:32,840
You added another Geter, and now you can safely access any of the Fifield's.

35
00:03:35,510 --> 00:03:37,140
And then you added another setar.

36
00:03:37,310 --> 00:03:41,750
Now you can update any of the Fifield's, there is nothing else to fix.


